<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>发送站内信</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__admin_static__/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="__admin_static__/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__admin_static__/css/animate.min.css" rel="stylesheet">
    <link href="__admin_static__/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">

    <link href="__admin_static__/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="__admin_static__/css/plugins/summernote/summernote.css" rel="stylesheet">
    <link href="__admin_static__/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">


</head>

<style>
    div.modal-backdrop.in{
        display: none !important;
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>发送站内信 <small>您可以发送站内信，填写通讯消息，客服会尽快与您联系</small></h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form method="post" class="form-horizontal" action="{:url('add')}" target="_self" onsubmit="javascript: return updateSubmit(this); ">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">提问标题</label>

                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="title" placeholder="请输入1-100个字(中文,英文,数字,符号)">
                                <span class="help-block m-b-none">必填)：请输入1-100个字(中文,英文,数字,符号)</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">联系手机号码</label>

                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="phone" placeholder="请输入正确的11位数的手机号码">
                                <span class="help-block m-b-none">必填)：为方便客服与您及时联系，请您填写手机号码哦</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">描述</label>

                            <div class="col-sm-10">
                                <input type="textarea" row="3" class="form-control" name="description" placeholder="请输入1-100个字(中文,英文,数字,符号)">
                                <span class="help-block m-b-none">必填)：对提问的简单描述，让客服人员更加容易理解您的意思哦</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">内容</label>
                            <div class="col-sm-10">
                                <input type="hidden" name="content" class="form-control">
                                <div class="ibox-content no-padding">
                                    <div class="summernote">

                                    </div>
                                </div>
                                <span class="help-block m-b-none">选填)：如果编辑器不够高度，请点击上方居中的三条横线进行拉高。</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" type="submit">发送站内信</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="__admin_static__/js/jquery.min.js?v=2.1.4"></script>
<script src="__admin_static__/js/bootstrap.min.js?v=3.3.5"></script>
<script src="__admin_static__/js/content.min.js?v=1.0.0"></script>
<script src="__admin_static__/js/plugins/iCheck/icheck.min.js"></script>
<script src="__admin_static__/js/plugins/summernote/summernote.min.js"></script>
<script src="__admin_static__/js/plugins/summernote/summernote-zh-CN.js"></script>
<script src="__admin_static__/js/base.js"></script>
<script>
    $(document).ready(function(){
        $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});

        //文本编辑器
        $(".summernote").summernote({
            height: 200,
            lang:"zh-CN",
            onImageUpload: function(files, editor, $editable) {
                sendFile(files[0],editor,$editable);
            }
        });
    });
    //编辑器上传图片
    function sendFile(file, editor, $editable){

        var filename = false;
        try{
            filename = file['name'];
        } catch(e){
            filename = false;
        }
        if(!filename){
            $(".note-alarm").remove();
        }

        //以上防止在图片在编辑器内拖拽引发第二次上传导致的提示错误
        data = new FormData();
        data.append("file", file);
        data.append("key",filename); //唯一性参数

        $.ajax({
            data: data,
            type: "POST",
            url: "{:url('upload_photo')}",
            cache: false,
            contentType: false,
            processData: false,
            success: function(data) {
                if(typeof data == 'string')
                {
                    data = JSON.parse(data);
                }
                if(data.error != 0){
                    alert(data.msg);
                    return;
                }
                //alert(url);
                editor.insertImage($editable, data.msg);
                //setTimeout(function(){$(".note-alarm").remove();},3000);
            },
            error:function(){
                alert("上传失败！");
                return;
                //setTimeout(function(){$(".note-alarm").remove();},3000);
            }
        });
    }

    //表单提交
    function updateSubmit(target)
    {
        $(target).find('input[name=content]').val(encodeURIComponent($('.summernote').code()));
        return true;
    }
</script>
</body>
</html>

